package com.wngbms.netty.gatewaydemo.filter;

import io.netty.handler.codec.http.FullHttpResponse;
import io.netty.handler.codec.http.HttpHeaders;

public class RemoveResponseHeaderFilter implements HttpResponseFilter {

    private String key;
    private HttpResponseFilter nextFilter;

    public RemoveResponseHeaderFilter() {
    }

    public RemoveResponseHeaderFilter(String key) {
        this.key = key;
    }

    public RemoveResponseHeaderFilter(HttpResponseFilter nextFilter) {
        this.nextFilter = nextFilter;
    }

    @Override
    public void filter(FullHttpResponse response) {
        HttpHeaders headers = response.headers();
        headers.remove(key);

        if (nextFilter != null) {
            nextFilter.filter(response);
        }
    }

    public void setNextFilter(HttpResponseFilter nextFilter) {
        this.nextFilter = nextFilter;
    }
}
